<template>
	<view>
		<city-select @cityClick="cityClick" 
		:activeCity="activeCity" :hotCity="hotCity" 
		:obtainCitys="obtainCitys" :isSearch="true" 
		ref="citys" @cityname="cityname"
		></city-select>
		<navigation></navigation>
	</view>
</template>

<script>
	import citySelect from "@/components/city-select/city-select.vue"
	import navigation from '@/components/navigation/navigation.vue';
	export default {
		data() {
			return {
				// 传递城市
				city:'',
				nowCity:'',
				//当前城市
				activeCity: {
					'cityCode': '320100',
					'cityName': '定位中...',
				},
				//热门城市
				hotCity: [{
						'cityCode': '320100',
						'cityName': '南京市',
					},
					{
						'cityCode': '110100',
						'cityName': '北京市',
					},
					{
						'cityCode': '110100',
						'cityName': '北京市',
					},
					{
						'cityCode': '110100',
						'cityName': '北京市',
					},{
						'cityCode': '110100',
						'cityName': '北京市',
					},{
						'cityCode': '110100',
						'cityName': '北京市',
					},{
						'cityCode': '110100',
						'cityName': '北京市',
					}
				],
				//显示的城市数据
				obtainCitys: [{
					'cityCode': '110100',
					'cityName': '北京'
				}, {
					'cityCode': '120100',
					'cityName': '天津'
				}, {
					'cityCode': '130100',
					'cityName': '石家庄市'
				}, {
					'cityCode': '130200',
					'cityName': '唐山市'
				}, {
					'cityCode': '130300',
					'cityName': '秦皇岛市'
				}, {
					'cityCode': '130400',
					'cityName': '邯郸市'
				}, {
					'cityCode': '130500',
					'cityName': '邢台市'
				}, {
					'cityCode': '130600',
					'cityName': '保定市'
				}]
			}
		},
		components: {
			citySelect,
			navigation
		},
		onLoad() {
			//动态更新数据
			setTimeout(()=> {
				this.obtainCitys = [{
					'cityCode': '650100',
					'cityName': '乌鲁木齐市'
				}, {
					'cityCode': '650200',
					'cityName': '克拉玛依市'
				}, {
					'cityCode': '652100',
					'cityName': '吐鲁番地区'
				}, {
					'cityCode': '652200',
					'cityName': '哈密地区'
				}, {
					'cityCode': '652300',
					'cityName': '昌吉回族自治州'
				}, {
					'cityCode': '652700',
					'cityName': '博尔塔拉蒙古自治州'
				}, {
					'cityCode': '652800',
					'cityName': '巴音郭楞蒙古自治州'
				}, {
					'cityCode': '652900',
					'cityName': '阿克苏地区'
				}]
				 // console.log ("更新数据")
			}, 5000);
		},
		methods: {
			// cityname() {
			// 	this.$emit('cityname',this.city)
			// }
			cityClick(item) {
				 // console.log (item.cityName),
				this.city = item.cityName
				uni.setStorageSync('temporary',this.city)
				uni.switchTab({
					url:'/pages/index/index'
				})
				// uni.reLaunch({
				// 		url:'/pages/index/index'
				// })
			}
		},
		onLoad() {
			uni.getLocation({
			     type: 'wgs84',
			      success: (res) => {
			       // console.log ('当前位置的经度：' + res.longitude);
			       // console.log ('当前位置的纬度：' + res.latitude);
			      // var point = (res.longitude, res.latitude);
				 const longitude = res.longitude;
				  const latitude = res.latitude;
				 uni.request({
					header:{
						"Content-Type": "application/text"
					},
					url:'https://restapi.amap.com/v3/geocode/regeo?location='+longitude+','+latitude+'&key=57909c51d546cb0c11d85a5737cc8588',
					success: (re) => {
						// if (!re.data.regeocode.addressComponent.city.length) {
						// 	this.areaList = re.data.regeocode.addressComponent.province;
						// } else {
						// 	this.areaList  = re.data.regeocode.addressComponent.city;
						// }
						//  // console.log (this);
						this.activeCity.cityName = re.data.regeocode.addressComponent.city
						 // console.log (this.activeCity.cityName)
						// if(re.statusCode === 200){
						// 	 // console.log ("获取中文街道地理位置成功")
						// }else{
						// 	 // console.log ("获取信息失败，请重试！")
						// }
					 }
				});
				},
			});
		}
	}
</script>

<style>
</style>
